﻿<%@ page language="java" import="com.newcrm.config.Const,com.newcrm.util.Util,com.newcrm.bean.*,java.util.List,java.util.Map" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  User user = (User) session.getAttribute("user");
  Map<Integer, CompanyInfo> companys = (Map<Integer, CompanyInfo>) application.getAttribute(Const.APPLICATION_COMPANYS);
  CompanyInfo companyInfo = companys.get(Integer.valueOf(user.companyId));
  List<Map<String, Object>> customerCategorys = companyInfo.customerCategorys;
  List<User> users = companyInfo.users;
  CustomerInfo customerInfo = (CustomerInfo)request.getAttribute("customerInfo");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title><%=Util.HTMLEncode(customerInfo.name)%> - 修改联系人信息</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/all.css?ver=<%=Const.VERSION%>">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/datepicker.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrap-datetimepicker.min.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/magnific-popup.css">
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-ui.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.bootstrap-growl.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/moment.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/daterangepicker.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.magnific-popup.min.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery.cookie.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/popbox.js"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/visiblecommon.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/commonCustomer_update.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/companySearch.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/area.js?ver=<%=Const.VERSION%>"></script>
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/common.js?ver=<%=Const.VERSION%>"></script>
  <script>
    var _share_type_user = '<%=Const.SHARE_TYPE_USER%>';
    var _share_type_group = '<%=Const.SHARE_TYPE_GROUP%>';
    var _visible_person = '<%=Const.VISIBLE_PERSON%>';
    var customerCategorys = new Array();
    <%if (customerCategorys != null) {
        for (Map<String, Object> category:customerCategorys) {
          String color = (String) category.get("Color");
          if (color == null || color.trim().length() == 0) {
            color = "000000";
          }%>
    customerCategorys.push({id:"<%=category.get("CategoryId")%>",name:"<%=Util.UEncode((String)category.get("CategoryName"))%>", color:"<%=color%>"});
      <%}
    } %>
    var allUsers = new Array();
    <%if (users != null) {
        for (User u:users) { %>
    allUsers.push({id:"<%=u.userId%>",name:"<%=Util.UEncode(u.name)%>",photo:"<%=u.imgPath%>"});
    <%  }
      } %>
    $(function() {
      var customerId = '<%=customerInfo.id%>';
    <% if (customerInfo.hasModifyRight(user, users)) {%>
      $('input[name="visible"]').filter('[value="<%=customerInfo.visible%>"]').attr('checked', true);
      $("input[name='visible']:checked").parent().next().show();
      <% if (customerInfo.visible == Const.VISIBLE_PERSON) {%>
      $("#permissionsId").val('<%=customerInfo.permissionsId%>');
      <%  if (customerInfo.shareUserIds != null && customerInfo.shareUserIds.trim().length() > 0) { %>
            // 个人共享的checkbox选择显示      
            $('input[name="shareUserId"]').val($("#oldShareUserIds").val().split(","));
      <%  } 
          if (customerInfo.shareGroupIds != null && customerInfo.shareGroupIds.trim().length() > 0) { %>
            // 部门共享的checkbox选择显示      
            $('input[name="shareGroupId"]').val($("#oldShareGroupIds").val().split(","));
     <%   } 
        } else {%>
      $("#groupPermissionsId").val("<%=customerInfo.permissionsId%>");
      <%}%>
    <%}%>
      $("#update_link").click(function(e) {
        e.preventDefault();
        $('#customerForm').submit();
      });
      $('#customerForm').submit(function(event){
        if ($("#peopleName").val() == "") {
          alert("请输入联系人姓名");
          $("#peopleName").focus();
          return false;
        }

        var emailinputError = false;
        $("input[name='email']").each(function (i) {
          if (!checkEmail($(this).val())) {
            emailinputError = true;
            alert("邮箱格式不正确");
            $(this).focus();
          }
        });
        if (emailinputError) {
          return false;
        }
        return true;
      });
      $("#companyName").autocomplete({
        source: "<%=request.getContextPath()%>/companyName?operation=list",
        select: function(event, ui ) {
          var _id = ui.item ? ui.item.id : "";
          $("#companyId").val(_id);
        }
      }).data("ui-autocomplete")._renderItem = function(ul, item) {
        return $( "<li></li>" )
          .data( "ui-autocomplete-item", item)
          .append("<a>" + item.label + "</a>")
          .appendTo(ul);
      };
    });
  </script>
</head>
<body class="parties">
  <jsp:include page="topNavi.jsp" flush="true"/>
  <div class="main-page">
    <table>
    <tr>
      <td class="main-body">
        <div class="topnavi">
          <div class='leftMenu'>
            <span>修改 <a href="<%=request.getContextPath()%>/people/<%=customerInfo.id%>"><%=Util.HTMLEncode(customerInfo.name)%></a></span>
          </div>
        </div>
        <div class="edit-page">
          <form action="<%=request.getContextPath()%>/people/<%=customerInfo.id%>/update" autocomplete="off" method="post" id="customerForm">
            <input type="hidden" name="deleteExtInfoIds" id="deleteExtInfoIds" value="">
            <input type="hidden" name="oldVisible" value="<%=customerInfo.visible%>">
            <input type="hidden" name="oldPermissionsId" value="<%=customerInfo.permissionsId%>">
            <input type="hidden" name="oldShareUserIds" id="oldShareUserIds" value="<%=customerInfo.shareUserIds%>">
            <input type="hidden" name="oldShareGroupIds" id="oldShareGroupIds" value="<%=customerInfo.shareGroupIds%>">           
            <div class="page_divider">
              <div class="primary_fields">
              <table cellpadding="0" cellspacing="0" class="contact_types">
              <tr class="name">
                <th><h2>姓名</h2></th>
                <td><input class="name autofocus" id="peopleName" name="peopleName" size="30" type="text" value="<%=Util.HTMLEncode(customerInfo.name)%>" /> <span id="txt" class="txt">(必填)</span></td>
              </tr>
              <tr class="title">
                <th><h2>职位</h2></th>
                <td><input class="autofocus" id="peopleTitle" name="peopleTitle" size="30" style="max-width: 97%" title="职位" type="text" value="<%=Util.HTMLEncode(customerInfo.title)%>" /></td>
              </tr>
              <tr class="company">
                <th><h2>公司</h2></th>
                <td><input class="autofocus" id="companyName" name="companyName" size="30" style="max-width: 97%" title="所属公司名称" type="text" value="<%=Util.HTMLEncode(customerInfo.parentName)%>" />
                  <input id="oldCompanyId" name="oldCompanyId" type="hidden" value="<%=customerInfo.parentId%>" />
                  <input id="companyId" name="companyId" type="hidden" value="<%=customerInfo.parentId%>" />
                </td>
              </tr>
            <jsp:include page="commonCustomer_update.jsp" flush="true">
              <jsp:param name="customerType" value="people"/>
            </jsp:include>
            <p class="submit">
              <a id="update_link" class="button blue" href="#"><i class="fa fa-check"></i> 修改联系人信息</a>
              <a class="button grey" href="<%=request.getContextPath()%>/people/<%=customerInfo.id%>"><i class="fa fa-times"></i> 取消</a>
            </p>
          </form>
        </div>
      </td>
      <td class="main-sidebar">
        <div class="content">
          <!--
          <h2 class="clearfix">联系人信息是否重复</h2>
          <ul>
            <li><a href="<%=request.getContextPath()%>/people/<%=customerInfo.id%>/duplicates">合并重复数据</a></li>
          </ul>
          -->
          <h2>撞单查询</h2>
          <div class="top5"><a href="#search-popup" class="open-popup-link button small grey"><i class="fa fa-search"></i> 撞单查询</a></div>
        </div>
      </td>
    </tr>
    </table>
  </div>

  <div id="search-popup" class="white-popup big mfp-hide">
    <div class="popup-title"><span class="title">撞单查询</span> <span class="popup-close-button"><i class="fa fa-times"></i>&nbsp;</span></div>
    <div class="popup-content">
      <div class="advsearch">
        <p>检索系统中的客户信息，避免撞单</p>
        <form id="search_customers" method="post" >
          <table class="searchDetail">
            <tr>
              <td>名称</td><td><input class="autofocus" type="text" value="" id="txtCompanyName"></td>
              <td>电话</td><td><input class="autofocus" type="text" value="" id="txtTel"></td>
            </tr>
            <tr>
              <td>邮箱</td><td><input class="autofocus" type="text" value="" id="txtEmail"></td>
              <td>QQ</td><td><input class="autofocus" type="text" value="" id="txtQQ">
              <span id="span_submit"><a id="search-link" class="button blue small" href="#"><i class="fa fa-search"></i> 搜索</a> <span id="noresult_msg">没检索到符合条件的结果</span></span>
              </td>
            </tr>
          </table>
        </form>
        <table class="searchresult" id="contactsList"></table>
      </div>
    </div>
  </div>
</body>
</html>